package com.sword.onlysword.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * com.sword.onlysword.config.DatasourceConfig
 * Created by SwordLiu on 2018-03-08.
 */
@Configuration
public class DatasourceConfig {

    @Value("${spring.datasource.db2.url}")
    private String dbUrl;
    @Value("${spring.datasource.db2.username}")
    private String username;
    @Value("${spring.datasource.db2.password}")
    private String password;

    @Bean(name = "db2")
    @Primary
    public DataSource dataSource(){
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(this.dbUrl);
        datasource.setUsername(username);
        datasource.setPassword(password);
        return datasource;
    }

}
